import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

/// toast 工具类
class CXToastUtils {
  static Color toastBgColor = const Color(0x80000000);

  static Color toastTextColor = Colors.white;

  static double toastFontSize = 16.0;

  static void init([Color? bgColor, Color? textColor, double? fontSize]) {
    toastBgColor = bgColor ?? toastBgColor;
    textColor = textColor ?? toastTextColor;
    toastFontSize = fontSize ?? toastFontSize;
  }

  /// 展示中间
  static void showCenter(String msg) {
    Fluttertoast.showToast(
      msg: msg,
      toastLength: Toast.LENGTH_SHORT,
      gravity: ToastGravity.CENTER,
      backgroundColor: toastBgColor,
      textColor: toastTextColor,
      fontSize: toastFontSize,
    );
  }

  // 展示底部
  static void show(String msg) {
    Fluttertoast.showToast(
      msg: msg,
      toastLength: Toast.LENGTH_SHORT,
      gravity: ToastGravity.BOTTOM,
      backgroundColor: toastBgColor,
      textColor: toastTextColor,
      fontSize: toastFontSize,
    );
  }

  static void showToast(String msg,
      {Toast toastLength = Toast.LENGTH_SHORT,
      double? fontSize,
      ToastGravity gravity = ToastGravity.BOTTOM,
      Color? bgColor,
      Color? textColor}) {
    Fluttertoast.showToast(
      msg: msg,
      toastLength: toastLength,
      gravity: gravity,
      fontSize: fontSize ?? toastFontSize,
      textColor: textColor ?? toastTextColor,
      backgroundColor: bgColor ?? toastBgColor,
    );
  }
}
